jQuery(document).ready(function() {
	
      
      
      $("#Deletes").click(function(){
      	var flag = "false";
      	var idValue="";
		$("#customer tbody :checkbox").each(function(i){
			if($(this).attr("checked")=="checked"){
				flag = "true";
				idValue = $(this).attr("value")+","+idValue;
			}
		});
		if(flag=="false"){
			alert("没有选择任何数据,请选择一条数据!");
		}else{
			if(confirm("警告!是否删除当前选中的数据？") == true){
				$.ajax({
    	            type:"post",
    	            url:"/crm/admin/customer!deletes.action",
    	            dataType:"json",
    	            data:"ids="+idValue,
    	            cache:false,
    	            beforeSend:function(XMLHttpRequest){
    	            },
    	            success:function(json){
    	            	result = json.result;
    	            	if(result){
    	            		alert("删除成功");
    	            		window.location.href="/crm/admin/customer!myCustomer.action";
    	            	}else{
    	            		alert("删除失败,请稍后重试！");
    	            	}
    	            },
    	           	complete:function(XMLHttpRequest,textStatus){
    	           	},
    	          	error:function(XMLHttpRequest,textStatus,errorThrown){
    	                   alert("网络错误，请稍后重试！");
    	          	}
                });
			}
		}
      });
      
      /**
       * 分享客户
      */
      $("#Shared").click(function(){
    	  
    	  $("#sharedCustomer").modal("show");
    	  
      });
      
      /**
       * 复制客户
       */
      $("#Duplicate").click(function(){
    	  
    	  
      });
      
      /**
       * 导出客户数据
       */
      $("#Export").click(function(){
    	  
    	  
      });
      /**
       * 导入客户数据
       */
      $("#Import").click(function(){
		  
		  
      });
}); 

 /**
 * 查看主要联系人的具体信息
 */
  function viewContacts(id){
	  $.ajax({
          type:"post",
          url:"/crm/admin/contacts!findById.action",
          dataType:"json",
          data:"contactsId="+id,
          cache:false,
          beforeSend:function(XMLHttpRequest){
          },
          success:function(json){
          	contacts = json.contacts;
          	$("input[name='lxr']").val(contacts.name);
              $("#gender").val(contacts.gender);
              $("input[name='telephone']").val(contacts.telephone);
              $("input[name='companyPhone']").val(contacts.phone);
              $("input[name='fax']").val(contacts.fax);
              $("input[name='email']").val(contacts.email);
              $("input[name='zipcode']").val(contacts.zipcode);
              $("input[name='address']").val(contacts.address);
              $("input[name='remarksToContacts']").val(contacts.remarks);
              $("input:radio").parents('span').removeClass('checked');
              var type = contacts.type;
              if(type=="Importance"){
              	$("input:radio[value='Importance']").parents('span').addClass('checked');
              }else if(type=="Secondary"){
              	$("input:radio[value='Secondary']").parents('span').addClass('checked');
              }else{
              	$("input:radio[value='']").parents('span').addClass('checked');
              }
              $("#ViewContacts").modal("show");
          },
         	complete:function(XMLHttpRequest,textStatus){
         	},
        	error:function(XMLHttpRequest,textStatus,errorThrown){
              alert("网络错误,重稍后重试!");
        	}
      });
  }
  
  /**
   * 填写客户跟踪信息
   * @param id
   */
  function tracking(id){
	  $.ajax({
          type:"post",
          url:"/crm/admin/customer!addTrackingInfo.action",
          dataType:"json",
          data:"customerId="+id,
          cache:false,
          beforeSend:function(XMLHttpRequest){
          },
          success:function(json){
	        	result = json.result;
	        	tracker = json.tracker;
	        	if(result){
	          	  customer = json.customer;
	          	  lxr = json.contactsList;
	          	  $("#customer_id").val(customer.id);
	          	  $("#CUSTO_NAME").val(customer.shortName);
	              $("#before_track_step").val(customer.currentStep);
	              $("#tracker").val(tracker);
	              $("#contacts_name" ).empty();
	              $(lxr).each(function(i){
			         $( "#contacts_name" ).append( "<option value='"+lxr[i].name+"'>" +lxr[i].name+"</option>" );
			      });
	              $("#ViewTracking").modal("show");
	        	}else{
	        		alert("程序异常,请联系系统开发人员!");
	        	}
            },
         	complete:function(XMLHttpRequest,textStatus){
         	},
        	error:function(XMLHttpRequest,textStatus,errorThrown){
              alert("网络错误,重稍后重试!");
        	}
      });
  }